<?php

namespace App\Http\Controllers\Api\Web\Device;

use App\Http\Controllers\Common\ApiController;
use App\Models\Device\Device;
use Illuminate\Http\Request;

class DeviceController extends ApiController{

    private $model = Device::class;

    public function lst(Request $request) {
        $page = $request->input('page',1);
        $pageSize = $request->input('pageSize',20);


        $conditions = $request->input();

        $records = (new $this->model())->getLst($conditions)->paginate($pageSize,$this->getCol,'page',$page);
        return responseSuccess($records->items(),$records->total());

    }

    public function add(Request $request) {
        $info = $request->input();

        $this->validate($request, [

        ],[],[

        ]);

        $this->model::updateOrCreate(['id'=>$info['id']??0],$info);
    }

    public function detail(Request $request){
        $id = $request->input('id',0);
        $records = $this->getDetail($this->model,[$id]);
        return responseSuccess($records->toArray(),1);
    }

    public function change(Request $request) {

        $ids = $request->input('ids',[]);
        $status = $request->input('status');
        return $this->changeColByIds($this->model, [$ids],compact('status'));
    }

    public function del(Request $request) {
        $ids = $request->input('ids',[]);
        return $this->delRecords($this->model, $ids);
    }
}
